package cn.com.headfree.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.headfree.base.controller.ResultData;

/**  
 * @Title  HumanExceptionHandler.java   
 * @Package cn.com.headfree.exception   
 * @Description 全局异常捕捉处理
 * @author yangwang 
 * @date  2020年3月25日 下午3:33:35   
 */
@ControllerAdvice
public class HumanExceptionHandler {
	private static final Logger LOG = LoggerFactory.getLogger(HumanExceptionHandler.class);

	@ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResultData errorHandler(Exception ex) {
		ResultData result = new ResultData();
        if(ex instanceof HumanException){
        	result.setErrorMsg(ex.getMessage());
            result.setSuccess(false);
            LOG.error(ex.getMessage(), ex);
        }
        return result;
    }
	
}
